home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu248.dms / pu248.adf / Intuition / Miscellaneous / Example2.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  3KB  |  93 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: Miscellaneous               Tulevagen 22       */
  8. /* File:    Example2.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example shows how to allocate and deallocate memory with help of */
  21. /* the functions AllocRemember(), and FreeRemember().                    */
  22.  
  23.  
  24. #include <intuition/intuition.h>
  25. #include <exec/memory.h>
  26.  
  27.  
  28. struct IntuitionBase *IntuitionBase;
  29.  
  30.  
  31. main()
  32. {
  33.   /* Declare and initialize a pointer to the first Remember structure: */
  34.   struct Remember *remember = NULL;
  35.   
  36.   /* Declare three memory pointers: */
  37.   CPTR memory1, memory2, memory3;
  38.  
  39.  
  40.  
  41.   /* Open the Intuition Library: */
  42.   IntuitionBase = (struct IntuitionBase *)
  43.     OpenLibrary( "intuition.library", 0 );
  44.   
  45.   if( IntuitionBase == NULL )
  46.     exit(); /* Could NOT open the Intuition Library! */
  47.  
  48.  
  49.  
  50.   /* Allocate 350 bytes of Chip memory, which is cleared: */
  51.   memory1 = AllocRemember( &remember, 350, MEMF_CHIP|MEMF_CLEAR );
  52.  
  53.   if( memory1 == NULL )
  54.   {
  55.     CloseLibrary( IntuitionBase );
  56.     exit();
  57.   }
  58.  
  59.  
  60.   /* Allocate 900 bytes of memory (any type, Fast if possible): */
  61.   memory2 = AllocRemember( &remember, 900, MEMF_PUBLIC );
  62.  
  63.   if( memory2 == NULL )
  64.   {
  65.     FreeRemember( &remember, TRUE );
  66.     CloseLibrary( IntuitionBase );
  67.     exit();
  68.   }
  69.  
  70.  
  71.   /* Allocate 100 bytes of Chip memory: *
  72.   memory3 = AllocRemember( &remember, 100, MEMF_CHIP );
  73.  
  74.   if( memory3 == NULL )
  75.   {
  76.     FreeRemember( &remember, TRUE );
  77.     CloseLibrary( IntuitionBase );
  78.     exit();
  79.   }
  80.  
  81.  
  82.  
  83.   /* Do whatever you want to do with the memory. */
  84.  
  85.  
  86.  
  87.   /* Deallocate all memory with one single call: */
  88.   FreeRemember( &remember, TRUE );
  89.  
  90.   /* Close the Intuition Library: */
  91.   CloseLibrary( IntuitionBase );
  92. }
  93.